<template>
    <div class="internalTransactionRecordsPage">
        <div class="search-wrap d-flex a-center flex-wrap">
            <div class="search-item d-flex a-center m-l20 m-b10">
                <label>合同号</label>
                <el-input class="m-l10" v-model="form.contractNo" placeholder="请输入合同号"></el-input>
            </div>
            <div class="search-item d-flex a-center m-l20 m-b10">
                <label>债务人</label>
                <el-input class="m-l10" v-model="form.debtor" placeholder="请输入债务人"></el-input>
            </div>
            <div class="search-item d-flex a-center m-l20 m-b10">
                <label>起始日期</label>
                <el-date-picker
                        class="m-l10"
                        v-model="form.dateTime"
                        value-format="YYYY-MM-DD"
                        type="daterange"
                        size="large"
                        range-separator="-"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"
                        @change="datePickerChange"
                />
            </div>
            <div class="search-item d-flex a-center m-l20 m-b10">
                <label>到期日期</label>
                <el-date-picker
                        class="m-l10"
                        v-model="form.valueTime"
                        value-format="YYYY-MM-DD"
                        type="daterange"
                        size="large"
                        range-separator="-"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"
                        @change="valueTimePickerChange"
                />
            </div>
            <div class="search-buttons m-l50 d-flex a-center m-b10">
                <el-button
                        color="#fc702b"
                        style="color:#fff;"
                        @click.prevent="onQuery"
                >查询</el-button>
                <el-button
                        color="#f0f0f0"
                        style="color: #000000"
                        @click.prevent="onReset"
                >重置</el-button>
                <el-divider direction="vertical" />
                <el-button
                        class="button_edit m-r10"
                        @click="onExport()"
                >
                    <svg-icon icon-class="project-detail-icon-derive" class="icon-export m-r5"></svg-icon>
                    一键导出
                </el-button>
                <el-button
                        class="button_edit"
                        @click="onImport()"
                >
                    <svg-icon icon-class="project-detail-icon-l-xiazai" class="icon-export m-r5"></svg-icon>
                    导入
                </el-button>
                <el-button
                    class="button_edit"
                    @click="toPath('fk')"
                >
                  放款记录
                </el-button>
                <el-button
                    class="button_edit"
                    @click="toPath('hk')"
                >
                    还款记录
                </el-button>
            </div>
        </div>
        <public-table
                ref="publicTableRef"
                class="m-t20"
                index
                radio
                :height="550"
                :indexWidth="'100'"
                :page="page"
                :tableData="tableData"
                :tableOption.sync="tableOption"
                @page-change="onPageChange"
                @handleSelectionChange="handleSelectionChange"
        >
        </public-table>
    </div>

    <import-file-popup
            :title="title"
            :is-tip="true"
            ref="importFilePopupRef"
            :interface-config="importFileInterfaceConfig"
            :template-config="templateConfig"
            @on-success="onQuery"
    />
</template>

<script setup>
import {onMounted, reactive, ref} from "vue";
import {
    ElSelect,
    ElOption,
    ElDivider,
    ElMessage,
    ElDatePicker, ElRadioGroup, ElRadioButton
} from "element-plus";
import PublicTable from "@/components/PublicTable.vue";

import {tableCommonFun} from "@/hooks/tableCommon";
import {bankManagementApi, companyApi} from "@/api/businessFinance";
import {useRouter} from "vue-router";
import ImportFilePopup from "@/components/importFilePopup.vue";
import router from "@/router";

const title = ref('导入CBS内部信贷');
const interfaceConfig = reactive({
    fileName:'businessFinance',
    apiPath:'CBS.getInnerCreditList',
});
const importFileInterfaceConfig = reactive({
    fileName:'businessFinance',
    apiPath:'CBS.importInnerCredit',
});
const exportConfig = reactive({
    fileName:'businessFinance',
    apiPath:'CBS.getBankInnerCreditLeadingOut',
    tableName:'CBS内部信贷导出'
});
const templateConfig = reactive({
    fileName:'businessFinance',
    apiPath:'CBS.downloadMB',
    param:{type:6},
    templateName:'CBS内部信贷模版'
});

const {
    form,
    page,
    tableOption,
    tableData,
    selectedArr,
    onQuery,
    onReset,
    onPageChange,
    getData,
    handleSelectionChange,
    onExport
}  = tableCommonFun(interfaceConfig,exportConfig);

form.value = {
    contractNo:'',
    debtor:'',
    dateTime:'',
    startTime:'',
    endTime:'',
    startDate:'',
    endDate:'',
    valueTime:''
}

tableOption.value = [
    { label: "信贷编号 ", prop: "creditNo", minWidth: 100 },
    { label: "合同状态 ", prop: "contractStatus", minWidth: 100 },
    { label: "合同号 ", prop: "contractNo", minWidth: 100 },
    { label: "贷款品种 ", prop: "loanType", minWidth: 100 },
    { label: "债权人名称 ", prop: "creditor", minWidth: 100 },
    { label: "债务人名称 ", prop: "debtor", minWidth: 100 },
    { label: "受托机构 ", prop: "trusteeOrg", minWidth: 100 },
    { label: "贷款期限 ", prop: "loanDate", minWidth: 100 },
    { label: "贷款期限 ", prop: "signDate", minWidth: 100 },
    { label: "起始日期 ", prop: "startDate", minWidth: 100 },
    { label: "到期日期 ", prop: "endDate", minWidth: 100 },
    { label: "合同金额 ", prop: "contractAmount", minWidth: 100 },
    { label: "贷款余额 ", prop: "loanBalance", minWidth: 100 },
    { label: "逾期金额 ", prop: "exceedAmount", minWidth: 100 },
    { label: "欠息金额 ", prop: "owedAmount", minWidth: 100 },
    { label: "经办人 ", prop: "creator", minWidth: 100 },
    { label: "经办时间 ", prop: "handleTime", minWidth: 100 },

];

const companyList = ref([]);
/**
 * 查公司列表
 */
const getCompanyList = () => {
    companyApi.getList({}).then(res=>{
        companyList.value = res.data;
    });
}

const visible = ref(false);

/**
 * 新增计息计算
 *
 */
const addHandle = () => {
    if(selectedArr.value.length===0){
        ElMessage.warning('请选择一条要操作的数据!');
        return;
    }
    visible.value = true;
}

/**
 * 起始日期
 */
const datePickerChange = (e) => {
    if(e===null || (e instanceof Array && e.length===0)){
        form.value.startTime = '';
        form.value.endTime = '';
        return;
    }
    form.value.startTime = e[0];
    form.value.endTime = e[1];
}

/**
 * 到期日期
 * @param e
 */
const valueTimePickerChange = (e) => {
    if(e===null || (e instanceof Array && e.length===0)){
        form.value.startDate = '';
        form.value.endDate = '';
        return;
    }
    form.value.startDate = e[0];
    form.value.endDate = e[1];
}

/**
 *
 * @param e
 */
const change = (e) => {
    if(e==='1'){
        interfaceConfig.apiPath = 'CBS.getInnerBalanceList';
    }
    if(e==='0'){
        interfaceConfig.apiPath = 'CBS.getInnerHisBalanceList';
    }
    page.current = 1;
    page.size = 50;
    getData({
        pageNum:1,
        pageSize:50
    });
}

const importFilePopupRef = ref(null);

/**
 * 导入
 */
const onImport = () => {
    importFilePopupRef.value.openPopup();
}

/**
 *
 * @param type
 */
const toPath = (type) => {
  if(type==='hk'){
      router.push({path:`/businessFinance/bankManagement/bankInformation/paymentHistory`})
  }
  if(type==='fk'){
      router.push({path:`/businessFinance/bankManagement/bankInformation/loanRecords`})
  }
}

onMounted(()=>{
    getData({
        pageNum:1,
        pageSize:50
    });
});
</script>

<style lang="scss" scoped>
.internalTransactionRecordsPage{
  .search-wrap{
    .search-item{

      .el-input{
        width: auto !important;
      }
    }
    .search-buttons{
      .icon-export{
        width: 18px;
        height: 18px;
      }
    }
  }
}

.public-dialog-content{
  .dialog-title-box{
    height: 30px;
    span{
      font-size: 15px;
      font-weight: 600;
    }
  }
}
</style>
